package com.cs.club.application.controller;

import com.cs.club.application.dtos.ClubAssetsDTO;
import com.cs.club.common.entity.BaseResponse;
import com.cs.club.common.utlis.ResultUtils;
import com.cs.club.domain.bos.ClubAssetsBO;
import com.cs.club.domain.service.ClubAssetsDomainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/assets")
public class ClubAssetsController {

    @Resource
    private ClubAssetsDomainService clubAssetsDomainService;

    /**
     * 添加资产
     */
    @PostMapping("/add")
    public BaseResponse<Boolean> addClubAssets(ClubAssetsDTO clubAssetsDTO) {
        // 输出日志
        log.info("添加资产请求参数：{}", clubAssetsDTO);
        ClubAssetsBO clubAssetsBO = new ClubAssetsBO();
        BeanUtils.copyProperties(clubAssetsDTO, clubAssetsBO);
        return ResultUtils.success(clubAssetsDomainService.addClubAssets(clubAssetsBO));
    }

    /**
     * 删除资产
     */
    @PostMapping("/delete")
    public BaseResponse<Boolean> deleteClubAssets(ClubAssetsDTO clubAssetsDTO) {
        // 输出日志
        log.info("删除资产请求参数：{}", clubAssetsDTO);
        ClubAssetsBO clubAssetsBO = new ClubAssetsBO();
        BeanUtils.copyProperties(clubAssetsDTO, clubAssetsBO);
        return ResultUtils.success(clubAssetsDomainService.deleteClubAssets(clubAssetsBO));
    }

    /**
     * 更新资产
     */
    @PostMapping("/update")
    public BaseResponse<Boolean> updateClubAssets(ClubAssetsDTO clubAssetsDTO) {
        // 输出日志
        log.info("更新资产请求参数：{}", clubAssetsDTO);
        ClubAssetsBO clubAssetsBO = new ClubAssetsBO();
        BeanUtils.copyProperties(clubAssetsDTO, clubAssetsBO);
        return ResultUtils.success(clubAssetsDomainService.updateClubAssets(clubAssetsBO));
    }

}
